﻿

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>沙驰经销商在线调拨平台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../layuiadmin/style/login.css" media="all">
    <style>
        .demo-carousel {
            height: 200px;
            line-height: 200px;
            text-align: center;

        }

        .code {
            width: 400px;
            margin: 0 auto;
        }

        .input-val {
            width: 295px;
            background: #ffffff;
            height: 2.8rem;
            padding: 0 2%;
            border-radius: 5px;
            border: none;
            border: 1px solid rgba(0,0,0,.2);
            font-size: 1.0625rem;
        }

        #canvas {
            float: right;
            display: inline-block;
            border: 1px solid #ccc;
            border-radius: 5px;
            cursor: pointer;
        }

        .btn {
            width: 100px;
            height: 40px;
            background: #f1f1f1;
            border: 1px solid #ccc;
            border-radius: 5px;
            margin: 20px auto 0;
            display: block;
            font-size: 1.2rem;
            color: #e22e1c;
            cursor: pointer;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
    </style>
</head>
<body>

    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>沙驰经销商在线调拨平台</h2>
                <p> </p>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <canvas id="canvas" width="120" height="35"></canvas>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom: 20px;">
                    <input type="checkbox" checked="checked" name="remember" id="remember" lay-skin="primary" title="记住密码">
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit" id="loginBtn">登 入</button>
                </div>
            </div>
        </div>

        <div class="layui-trans layadmin-user-login-footer">

            <p>© 2022</p>

        </div>

        <!--<div class="ladmin-user-login-theme">
          <script type="text/html" template>
            <ul>
              <li data-theme=""><img src="{{ layui.setter.base }}style/res/bg-none.jpg"></li>
              <li data-theme="#03152A" style="background-color: #03152A;"></li>
              <li data-theme="#2E241B" style="background-color: #2E241B;"></li>
              <li data-theme="#50314F" style="background-color: #50314F;"></li>
              <li data-theme="#344058" style="background-color: #344058;"></li>
              <li data-theme="#20222A" style="background-color: #20222A;"></li>
            </ul>
          </script>
        </div>-->

    </div>
    <script src="../layuiadmin/js/jquery.min2.1.4.js"></script>
    <script src="../layuiadmin/layui/layui.js"></script>
    <script src="../layuiadmin/js/jshelp.js"></script>
    <script src="../layuiadmin/js/cookie.js"></script>

    <script>
        //画验证码
        function draw(show_num) {
            var canvas_width = $('#canvas').width();
            var canvas_height = $('#canvas').height();
            var canvas = document.getElementById("canvas");//获取到canvas的对象，演员
            var context = canvas.getContext("2d");//获取到canvas画图的环境，演员表演的舞台
            canvas.width = canvas_width;
            canvas.height = canvas_height;
            var sCode = "A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0";
            var aCode = sCode.split(",");
            var aLength = aCode.length;//获取到数组的长度

            for (var i = 0; i <= 3; i++) {
                var j = Math.floor(Math.random() * aLength);//获取到随机的索引值
                var deg = Math.random() * 30 * Math.PI / 180;//产生0~30之间的随机弧度
                var txt = aCode[j];//得到随机的一个内容
                show_num[i] = txt.toLowerCase();
                var x = 10 + i * 20;//文字在canvas上的x坐标
                var y = 20 + Math.random() * 8;//文字在canvas上的y坐标
                context.font = "bold 23px 微软雅黑";

                context.translate(x, y);
                context.rotate(deg);

                context.fillStyle = randomColor();
                context.fillText(txt, 0, 0);

                context.rotate(-deg);
                context.translate(-x, -y);
            }
            for (var i = 0; i <= 5; i++) { //验证码上显示线条
                //context.strokeStyle = randomColor();
                //context.beginPath();
                //context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height);
                //context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height);
                //context.stroke();
            }
            for (var i = 0; i <= 30; i++) { //验证码上显示小点
                //context.strokeStyle = randomColor();
                //context.beginPath();
                //var x = Math.random() * canvas_width;
                //var y = Math.random() * canvas_height;
                //context.moveTo(x, y);
                //context.lineTo(x + 1, y + 1);
                //context.stroke();
            }
        }

        function randomColor() {//得到随机的颜色值
            var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            return "rgb(" + r + "," + g + "," + b + ")";
        }

    </script>
    <script>
        layui.config({
            base: '../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'user', 'layer'], function () {
            var $ = layui.$
                , setter = layui.setter
                , admin = layui.admin
                , form = layui.form
                , router = layui.router()
                , search = router.search
                , layer = layui.layer;
            form.render();
            var show_num = [];
            draw(show_num);
            $("#canvas").on('click', function () {
                draw(show_num);
            })
            var num = show_num.join("");
            //提交
            form.on('submit(LAY-user-login-submit)', function (obj) {
                var val = $("#LAY-user-login-vercode").val().toLowerCase();
                var num = show_num.join("");
                if (val == num) {
                    $("#LAY-user-login-vercode").val('');
                    //draw(show_num);
                }
                else {
                    layer.msg('验证码错误！请重新输入！', { icon: 5 });
                    $("#LAY-user-login-vercode").val('');
                    draw(show_num);
                    return
                }
                var loginUsername = $('#LAY-user-login-username').val();
                var loginPassword = $('#LAY-user-login-password').val();
                var params = {};
                params.LOGINID = loginUsername;
                params.PASSWORD = loginPassword;
                var loginLoadIndex = layer.load(2);
                $('#loginBtn').val("正在登录...");
                $.ajax({
                    type: 'post',
                    url: 'ashx/login.ashx?type=post',
                    contentType: "application/json",
                    dataType: "json",
                    data: JSON.stringify(params),
                    success: function (data) {
                        layer.close(loginLoadIndex);
                        if (data.state == "true") {
                            //如果记住密码，7天
                            if ($("#remember").prop("checked") == true) {
                                $.cookie("id", data.id, { path: "/", expiress: 7, sucue: true });//用户id，数量为天
                                $.cookie("loginid", data.loginid, { path: "/", expiress: 7, sucue: true });//登录账号
                                $.cookie("username", data.username, { path: "/", expiress: 7, sucue: true });//用户名
                                $.cookie("role", data.role, { path: "/", expiress: 7, sucue: true });//权限
                                $.cookie("islookme", data.islookme, { path: "/", expiress: 7, sucue: true });//权限
                                $.cookie("phone", data.phone, { path: "/", expiress: 7, sucue: true });//权限
                            } else {
                                $.cookie("id", data.id, { path: "/", sucue: true });//用户id
                                $.cookie("loginid", data.loginid, { path: "/", sucue: true });//登录账号
                                $.cookie("username", data.username, { path: "/", sucue: true });//用户名
                                $.cookie("role", data.role, { path: "/", sucue: true });//权限
                                $.cookie("islookme", data.islookme, { path: "/", sucue: true });//权限
                                $.cookie("phone", data.phone, { path: "/", sucue: true });//权限
                            }
                            location.href = '../views/index.html'; //服务器
                            //location.href = '../index.html'; //后台主页
                        }
                        else {
                            layer.msg('用户名或密码错误', { icon: 5 });
                        }
                    },
                    error: function () {
                        layer.close(loginLoadIndex);
                        $('#loginBtn').val("登录");
                    }
                });
            });
            $('#LAY-user-login-vercode').on('keydown', function (event) {
                if (event.keyCode == 13) {
                    $("#loginBtn").trigger("click");
                    return false
                }
            });
        });
    </script>
</body>
</html>